<?php
//require_once ('protected\extensions\YiiMongoDbSuite\EMongoDocument.php');
class User extends MrMongoDocument {
	public $email;
	public $password;
	public $name;
	public $gender;
	public $city;
	public $domain;
	public $desc;
	
	/**
	 * This method have to be defined in every Model
	 * @return string MongoDB collection name, witch will be used to store documents of this model
	 */
	public function getCollectionName() {
		return 'users';
	}
	
	public function rules() {
		return array (array ('password ', 'required' ), array ('email', 'email' ), array ('email', 'EMongoUniqueValidator', 'on' => array ('insert' ) ) );
	}
	public function attributeLabels() {
		return array ('email' => 'Email' );
	}
	
	public function getPage() {
		return Page::findByUserId ( $this->_id );
	}
	
	public function getUid() {
		return $this->_id;
	}
	
	/*SEARCH*/
	
	public static function findByUid($uid) {
		$uid = new MongoId ( $uid );
		return self::model ()->findByAttributes ( array ('_id' => $uid ) );
	}
	  
	public static function model($className = __CLASS__) {
		return parent::model ( $className );
	}
	
	protected function beforeSave() {
		$this->name = strtolower ( $this->name );
		return true;
	}
}
?>